﻿using BingWallpaper.Models.Entitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BingWallpaper.Services
{
    public class BingWallpaperBLL
    {
        ///// <summary>
        ///// 保存
        ///// </summary>
        ///// <param name="model"></param>
        ///// <returns></returns>
        //public int Add(BingImagesModel model)
        //{
        //    return DAL.DBContext.GetDbContext().Insertable<Models.Entitys.BingImagesModel>(model).ExecuteCommand(); 
        //}

        /// <summary>
        /// 保存图片有重复的不保存
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Save(BingImagesModel model)
        {


            if (DAL.DBContext.GetDbContext().Queryable<BingImagesModel>().Where(it => it.FullStartDate == model.FullStartDate).Count() > 0)
            {
                return 0;
            }
            else
            {
                return DAL.DBContext.GetDbContext().Insertable<Models.Entitys.BingImagesModel>(model).ExecuteCommand();
            }

        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        public List<BingImagesModel> GetList()
        {



            return DAL.DBContext.GetDbContext().Queryable<Models.Entitys.BingImagesModel>().OrderBy(" id desc ").ToList();


        }
    }
}
